#include "PuzzlePoint.h"
#include <MultiWidgets/FadeAnimator.hpp>

PuzzlePoint::PuzzlePoint(){
	setBackgroundColor(1,1,1,1);
	setOpacity(0);
	setSize(7,7);
	setFixed();
}

bool PuzzlePoint::isInside(Nimble::Vector2 v) const {
	float radius = 2.f * width();
	
	// Compute the center of the circles
    Nimble::Vector2 center = 0.5f * size().toVector();

	 // Compute the distance of the input point from the center
    float distance = (v - center).length();

	// If the distance is smaller than the out radius and larger than the inner
    // radius the point is inside our donut


    return (distance < radius);
}
void PuzzlePoint::renderBackground(Luminous::RenderContext & r) const {
	Luminous::Style s;
	Radiant::Color color =backgroundColor();
	color.setAlpha(0.5);
	s.setStrokeColor(color);
    s.setStrokeWidth(2);
	s.setFillColor(backgroundColor());

	// Compute the center of the widget in local coordinates
    Nimble::Vector2 center = 0.5f * size().toVector();

    // Compute the radius of the donut in local coordinates
    float radius = 0.5f * width();
	// This functions draws the main circle
	r.drawCircle(center, radius, s, 64, 0.f, Nimble::Math::TWO_PI);
}
void PuzzlePoint::singleTap(MultiWidgets::GrabManager &gm, const MultiWidgets::TrackedObjectArray &objects) {
		setInputFlags(INPUT_NONE);
		eventSend("clicked");
		MultiWidgets::FadeAnimator::fadeIn(*this, 0.3);
		
}
